package com.gxuwz.medical.domain.prove;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.gxuwz.medical.database.DbUtil;

public class Prove {
	public static final String PROVE_EXPIRE_ERROR="不在慢性病证有效期内";
	public static final String ILLNAME_NOT_MATCH_ERROR="疾病名称与慢性病证不匹配";
	public static final String NO_PROVE_ERROR="查询慢性病证信息失败";
	private String proveno;
	private String ybcardno;
	private String idcard;
	private String illname;
	private Date stime;
	private Date etime;
	public Prove(){};
	public Prove(String ybcardno, String idcard, String illname, Date stime,
			Date etime) {
		super();
		createProve();
		this.ybcardno = ybcardno;
		this.idcard = idcard;
		this.illname = illname;
		this.stime = stime;
		this.etime = etime;
	}
	
	public boolean hasProve(String ybcardno) throws SQLException{
		DbUtil db = new DbUtil();
		Connection conn=db.getConn();
		Statement stmt = conn.createStatement();
		String sql ="select * from prove where ybcardno='"+ybcardno+"'";
		ResultSet rs =db.executeQuery(stmt, sql);
		if(rs.next()){
			return true;
		}
		return false;
	}
	
	public boolean isExpire(){
		Date now = new Date();
		if(now.after(stime)&&now.before(etime))//在有效期内
			return false;
		return true;
	}
	public Prove(String proveno, String ybcardno, String idcard,
			String illname, Date stime, Date etime) {
		super();
		this.proveno = proveno;
		this.ybcardno = ybcardno;
		this.idcard = idcard;
		this.illname = illname;
		this.stime = stime;
		this.etime = etime;
	}
	private void createProve() {
		this.proveno = "MXBZ"+String.valueOf(new Date().getTime());
	}
	public String getProveno() {
		return proveno;
	}
	public void setProveno(String proveno) {
		this.proveno = proveno;
	}
	public String getYbcardno() {
		return ybcardno;
	}
	public void setYbcardno(String ybcardno) {
		this.ybcardno = ybcardno;
	}
	public String getIdcard() {
		return idcard;
	}
	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}
	public String getIllname() {
		return illname;
	}
	public void setIllname(String illname) {
		this.illname = illname;
	}
	public Date getStime() {
		return stime;
	}
	public void setStime(Date stime) {
		this.stime = stime;
	}
	public Date getEtime() {
		return etime;
	}
	public void setEtime(Date etime) {
		this.etime = etime;
	}
	
}
